package com.sinog.biz.schedule;

import com.alibaba.fastjson.JSONObject;
import com.sinog.biz.BizApplication;
import com.sinog.biz.service.api.DataTransmissionService;
import com.sinog.biz.util.DataSourceCheckUtils;
import com.sinog.core.domain.PrisonerFx;
import com.sinog.core.domain.PrisonerMain;
import com.sinog.core.domain.PrisonerSr;
import com.sinog.core.domain.PrisonerZn;
import com.sinog.core.domain.UserInterFaceEntity;
import com.sinog.core.model.MultimediaInfo;
import com.sinog.core.util.Hex;
import com.sinog.core.utilbean.Constants;
import com.sinog.core.utilbean.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * @desc 预安置人员数据录入，方式2：中间库方式 - (监狱、社区矫正、看守所) - 达梦数据库版本
 * @author lzq
 * @date 2020-12-01 2:36 下午
 */
@Slf4j
@Component
@Configuration
@ConditionalOnProperty(name = "gkzx.azbj.outerInterface.db.dm.open", havingValue = "true")
public class ShadowForDmSchedule {

    private static final Pattern PATTERN = Pattern.compile("\\d{9}");
    /**
     * 中间库数据源
     */
    private JdbcTemplate dmJdbcTemplate;
    /**
     * 安置帮教库数据源
     */
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private DataTransmissionService dataTransmissionService;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 定时从中间库拉取数据保存到本地库(生产上每天晚11点跑：0 0 23 * * ?)，本地测试每分钟执行一次：0 0/1 * * * ?
     */
    @Scheduled(cron = "${gkzx.azbj.outerInterface.db.dm.cron}")
    private void predictWarningShadowTask() {
        log.info("\n>>>>>>>>>>>starting......从中间库同步预安置人员数据<<<<<<<<<<");
        ApplicationContext applicationContext = BizApplication.applicationContext;
        if(!ObjectUtils.allNotNull(dmJdbcTemplate)) {
            dmJdbcTemplate = (JdbcTemplate)applicationContext.getBean("dmJdbcTemplate");
        }
        if(!ObjectUtils.allNotNull(jdbcTemplate)) {
            jdbcTemplate = (JdbcTemplate)applicationContext.getBean("jdbcTemplate");
        }
        //检测全部数据源是否可用
        boolean allRunning = DataSourceCheckUtils.checkRunningStatus(dmJdbcTemplate,jdbcTemplate);
        if(true){
            //1、定义sql：查询---> 中间库prisoner_main表昨天，并且状态是0的数据
            String mainSql = "select * from prisoner_main where state='0' " +
                    "and pri_num not in (select pri_num from prisoner_main where pri_num is not null group by pri_num having count(1)>1) limit 0,500";
            //2、执行sql：返回---> 中间库prisoner_main表昨天，并且状态是0的数据
            List<Map<String,Object>> mainLists = dmJdbcTemplate.queryForList(mainSql);
            //3、遍历每一条主表数据，并且根据【对方的犯罪编号】查询出相关的服刑表、社会关系表、子女表、多媒体信息表
            Date date1 = new Date();
            for(Map<String,Object> mainMaps : mainLists) {
                //3.1、取出当前main表数据map
                //3.2、定义PrisonerMain
                PrisonerMain prisonerMain = new PrisonerMain();
                //3.3、取出map中prisonerMain属性
                String prinum = (String)mainMaps.get("pri_num");
                String azbjPrinum1 = (String)mainMaps.get("azbj_prinum");
                String account = (String)mainMaps.get("account");
                String pname = (String)mainMaps.get("p_name");
                String usedname = (String)mainMaps.get("used_name");
                String sex = (String)mainMaps.get("sex");
                String nationality = (String)mainMaps.get("nationality");
                if(Constants.Number.NUM_ONE.equals(nationality.length())) {
                    nationality = Constants.NumberStr.NUM_STR_ZERO + nationality;
                }
                String idType = (String)mainMaps.get("idType");
                String idnum = (String)mainMaps.get("id_num");
                Date age = (Date)mainMaps.get("age");
                String education = (String)mainMaps.get("education");
                Date addtime = (Date)mainMaps.get("addtime");
                String priAddr = (String)mainMaps.get("pri_addr");
                String nativepro = (String)mainMaps.get("nativepro");
                String nativecity = (String)mainMaps.get("nativecity");
                String nativecou = (String)mainMaps.get("nativecou");
                String nativevill = (String)mainMaps.get("nativevill");
                if(!StringUtils.isEmpty(nativevill) && !PATTERN.matcher(nativevill).matches()) {
                    nativevill = "";
                }
                String nativenum = (String)mainMaps.get("nativenum");
                String placepro = (String)mainMaps.get("placepro");
                String placecity = (String)mainMaps.get("placecity");
                String placecou = (String)mainMaps.get("placecou");
                String placevill = (String)mainMaps.get("placevill");
                if(!StringUtils.isEmpty(placevill) && !PATTERN.matcher(placevill).matches()) {
                    placevill = "";
                }
                String placenum = (String)mainMaps.get("placenum");
                String arrestpro = (String)mainMaps.get("arrestpro");
                String arrestcity = (String)mainMaps.get("arrestcity");
                String arrestcou = (String)mainMaps.get("arrestcou");
                String arrestvill = (String)mainMaps.get("arrestvill");
                if(!StringUtils.isEmpty(arrestvill) && !PATTERN.matcher(arrestvill).matches()) {
                    arrestvill = "";
                }
                String arrestnum = (String)mainMaps.get("arrestnum");
                String investigatepro = (String)mainMaps.get("investigate_pro");
                String investigatecity = (String)mainMaps.get("investigate_city");
                String investigatecou = (String)mainMaps.get("investigate_cou");
                String investigatevill = (String)mainMaps.get("investigate_vill");
                if(!StringUtils.isEmpty(investigatevill) && !PATTERN.matcher(investigatevill).matches()) {
                    investigatevill = "";
                }
                String investigatenum = (String)mainMaps.get("investigate_num");
                //3.4、封装实体类prisonerMain
                prisonerMain.setPriNum(azbjPrinum1);
                prisonerMain.setPName(pname);
                prisonerMain.setUsedName(usedname);
                prisonerMain.setSex(sex);
                prisonerMain.setNationality(nationality);
                prisonerMain.setIdType(idType);
                prisonerMain.setIdNum(idnum);
                prisonerMain.setAge(age);
                prisonerMain.setEducation(education);
                prisonerMain.setAddtime(addtime);
                prisonerMain.setPriAddr(priAddr);
                prisonerMain.setNativepro(nativepro);
                prisonerMain.setNativecity(nativecity);
                prisonerMain.setNativecou(nativecou);
                prisonerMain.setNativevill(nativevill);
                prisonerMain.setNativenum(nativenum);
                prisonerMain.setPlacepro(placepro);
                prisonerMain.setPlacecity(placecity);
                prisonerMain.setPlacecou(placecou);
                prisonerMain.setPlacevill(placevill);
                prisonerMain.setPlacenum(placenum);
                prisonerMain.setArrestpro(arrestpro);
                prisonerMain.setArrestcity(arrestcity);
                prisonerMain.setArrestcou(arrestcou);
                prisonerMain.setArrestvill(arrestvill);
                prisonerMain.setArrestnum(arrestnum);
                prisonerMain.setInvestigatePro(investigatepro);
                prisonerMain.setInvestigateCity(investigatecity);
                prisonerMain.setInvestigateCou(investigatecou);
                prisonerMain.setInvestigateVill(investigatevill);
                prisonerMain.setInvestigateNum(investigatenum);
                prisonerMain.setCreateUser(account);
                prisonerMain.setCreateTime(date1);
                prisonerMain.setUpdateUser(account);
                prisonerMain.setUpdateTime(date1);
                //3.5、定义sql：根据【对方犯罪编号】查询---> 中间库prisoner_fx数据
                String fxSql = "select * from \"azbjMiddle\".prisoner_fx where pri_num='" + prinum + "'";
                //3.6、执行sql：返回---> 中间库prisoner_fx表数据
                List<Map<String,Object>> fxLists = dmJdbcTemplate.queryForList(fxSql);
                //3.7、定义PrisonerFx
                PrisonerFx prisonerFx = null;
                for(Map<String,Object> fxList : fxLists) {
                    prisonerFx = new PrisonerFx();
                    //3.8 取出map中prisonerFx属性
                    String critype = (String)fxList.get("Critype");
                    String precri = (String)fxList.get("Precri");
                    String addpenalty = (String)fxList.get("Addpenalty");
                    String jinengtype = (String)fxList.get("jinengtype");
                    String pritime = (String)fxList.get("Pritime");
                    String arrjg = (String)fxList.get("arr_jg");
                    Date pribegin = (Date)fxList.get("Pri_begin");
                    Date pristop = (Date)fxList.get("Pri_stop");
                    String aftype = (String)fxList.get("Aftype");
                    String bqzy = (String)fxList.get("bqzy");
                    String fzlx = (String)fxList.get("fzlx");
                    String canji = (String)fxList.get("canji");
                    //3.9 封装实体类prisonerFx
                    prisonerFx.setCritype(critype);
                    prisonerFx.setPrecri(precri);
                    prisonerFx.setAddpenalty(addpenalty);
                    prisonerFx.setJinengtype(jinengtype);
                    prisonerFx.setPritime(pritime);
                    prisonerFx.setArrJg(arrjg);
                    prisonerFx.setPriBegin(pribegin);
                    prisonerFx.setPriStop(pristop);
                    prisonerFx.setAftype(aftype);
                    prisonerFx.setBqzy(bqzy);
                    prisonerFx.setCreateUser(account);
                    prisonerFx.setCreateTime(date1);
                    prisonerFx.setUpdateUser(account);
                    prisonerFx.setUpdateTime(date1);
                    if(!StringUtils.isEmpty(critype) && StringUtils.isEmpty(fzlx)) {
                        String[] critypes = critype.split(",");
                        List<String> fzlxs = new ArrayList<>(16);
                        for(String c : critypes) {
                            //根据罪名查询对应的犯罪类型
                            String fzlxTemp = (String)stringRedisTemplate.opsForHash().get("critypeAndFzlx",c);
                            if(!fzlxs.contains(fzlxTemp)) {
                                fzlxs.add(fzlxTemp);
                            }
                        }
                        String temp = "";
                        for(String f : fzlxs) {
                            if(!StringUtils.isEmpty(temp)) {
                                temp = new StringBuilder(16).append(temp).append(",").append(f).toString();
                            } else {
                                temp = f;
                            }
                        }
                        fzlx = temp;
                    }
                    prisonerFx.setFzlx(fzlx);
                    prisonerFx.setCanji(canji);
                }
                //3.10、定义sql：根据【对方犯罪编号】查询---> 中间库prisoner_sr数据
                String srSql = "select * from \"azbjMiddle\".prisoner_sr where pri_num='" + prinum + "'";
                //3.11、执行sql：返回---> 中间库prisoner_sr表数据
                List<Map<String,Object>> srLists = dmJdbcTemplate.queryForList(srSql);
                //3.12、定义PrisonerSr
                List<PrisonerSr> prisonerSrs = new ArrayList<>(16);
                for(Map<String,Object> srList : srLists) {
                    PrisonerSr prisonerSr = new PrisonerSr();
                    //3.13 取出map中PrisonerSr属性
                    String thename = (String)srList.get("thename");
                    String relation = (String)srList.get("relation");
                    Date srage = (Date)srList.get("age");
                    String danwei = (String)srList.get("danwei");
                    String tel = (String)srList.get("tel");
                    String mobile = (String)srList.get("mobile");
                    String addrpro = (String)srList.get("addrpro");
                    String addrcity = (String)srList.get("addrcity");
                    String addrcou = (String)srList.get("addrcou");
                    String addrvil = (String)srList.get("addrvil");
                    if(!StringUtils.isEmpty(addrvil) && !PATTERN.matcher(addrvil).matches()) {
                        addrvil = "";
                    }
                    String addrdetail = (String)srList.get("addrdetail");
                    String idnumber = (String)srList.get("idnumber");
                    if("000000000000000".equals(idnumber)) {
                        idnumber = "";
                    }
                    //3.14 封装实体类PrisonerSr
                    prisonerSr.setThename(thename);
                    prisonerSr.setRelation(relation);
                    prisonerSr.setAge(srage);
                    prisonerSr.setTel(!StringUtils.isEmpty(tel) && "无".equals(tel) ? "" : tel);
                    prisonerSr.setDanwei(danwei);
                    prisonerSr.setMobile(!StringUtils.isEmpty(mobile) && "无".equals(mobile) ? "" : mobile);
                    prisonerSr.setAddrpro(addrpro);
                    prisonerSr.setAddrcity(addrcity);
                    prisonerSr.setAddrcou(addrcou);
                    prisonerSr.setAddrvil(addrvil);
                    prisonerSr.setAddrdetail(addrdetail);
                    prisonerSr.setIdnumber(idnumber);
                    prisonerSr.setCreateUser(account);
                    prisonerSr.setCreateTime(date1);
                    prisonerSr.setUpdateUser(account);
                    prisonerSr.setUpdateTime(date1);
                    //3.15 添加PrisonerSr到list
                    prisonerSrs.add(prisonerSr);
                }
                //3.16、定义sql：根据【对方犯罪编号】查询---> 中间库prisoner_zn数据
                String znSql = "select * from \"azbjMiddle\".prisoner_zn where pri_num='" + prinum + "'";
                //3.17、执行sql：返回---> 中间库prisoner_zn表数据
                List<Map<String,Object>> znLists = dmJdbcTemplate.queryForList(znSql);
                //3.18、定义prisonerZn
                List<PrisonerZn> prisonerZns = new ArrayList<>(16);
                for(Map<String,Object> znList : znLists) {
                    PrisonerZn prisonerZn = new PrisonerZn();
                    //3.19 取出map中prisonerZn属性
                    String name = (String)znList.get("name");
                    String znsex = (String)znList.get("sex");
                    Date znage = (Date)znList.get("age");
                    String jianhuren = (String)znList.get("jianhuren");
                    String kunnan = (String)znList.get("kunnan");
                    String shixue = (String)znList.get("shixue");
                    String liulang = (String)znList.get("liulang");
                    String fanzui = (String)znList.get("fanzui");
                    String znsfId = (String)znList.get("znsf_id");
                    String znnativepro = (String)znList.get("nativepro");
                    String znnativecity = (String)znList.get("nativecity");
                    String znnativecou = (String)znList.get("nativecou");
                    String znnativevill = (String)znList.get("nativevill");
                    if(!StringUtils.isEmpty(znnativevill) && !PATTERN.matcher(znnativevill).matches()) {
                        znnativevill = "";
                    }
                    String znnativenum = (String)znList.get("nativenum");
                    String znplacepro = (String)znList.get("placepro");
                    String znplacecity = (String)znList.get("placecity");
                    String znplacecou = (String)znList.get("placecou");
                    String znplacevill = (String)znList.get("placevill");
                    if(!StringUtils.isEmpty(znplacevill) && !PATTERN.matcher(znplacevill).matches()) {
                        znplacevill = "";
                    }
                    String znplacenum = (String)znList.get("placenum");
                    //3.20 封装实体类prisonerZn
                    prisonerZn.setName(name);
                    prisonerZn.setSex(znsex);
                    prisonerZn.setAge(znage);
                    prisonerZn.setJianhuren(jianhuren);
                    prisonerZn.setKunnan(kunnan);
                    prisonerZn.setShixue(shixue);
                    prisonerZn.setLiulang(liulang);
                    prisonerZn.setFanzui(fanzui);
                    prisonerZn.setZnsfId(znsfId);
                    prisonerZn.setNativepro(znnativepro);
                    prisonerZn.setNativecity(znnativecity);
                    prisonerZn.setNativecou(znnativecou);
                    prisonerZn.setNativevill(znnativevill);
                    prisonerZn.setNativenum(znnativenum);
                    prisonerZn.setPlacepro(znplacepro);
                    prisonerZn.setPlacecity(znplacecity);
                    prisonerZn.setPlacecou(znplacecou);
                    prisonerZn.setPlacevill(znplacevill);
                    prisonerZn.setPlacenum(znplacenum);
                    prisonerZn.setCreateUser(account);
                    prisonerZn.setCreateTime(date1);
                    prisonerZn.setUpdateUser(account);
                    prisonerZn.setUpdateTime(date1);
                    //3.21 添加prisonerZn到list
                    prisonerZns.add(prisonerZn);
                }
                //3.22、定义sql：根据【对方犯罪编号】查询---> 中间库prisoner_multimedia数据
                String mediaSql = "select * from \"azbjMiddle\".prisoner_multimedia where pri_num='" + prinum + "'";
                //3.23、执行sql：返回---> 中间库prisoner_multimedia表数据
                List<Map<String,Object>> mediaLists = dmJdbcTemplate.queryForList(mediaSql);
                //3.24、定义multimediaInfo
                List<MultimediaInfo> multimediaInfos = new ArrayList<>(16);
                for(Map<String,Object> mediaList : mediaLists) {
                    MultimediaInfo multimediaInfo = new MultimediaInfo();
                    //3.25 取出map中multimediaInfo属性
                    String taskId = (String)mediaList.get("task_id");
                    String imgstr = (String)mediaList.get("imgstr");
                    String filetype = (String)mediaList.get("filetype");
                    //3.26 封装实体类multimediaInfo
                    multimediaInfo.setTaskId(taskId);
                    multimediaInfo.setImgstr(imgstr);
                    multimediaInfo.setFiletype(filetype);
                    //3.27 添加multimediaInfo到list
                    multimediaInfos.add(multimediaInfo);
                }
                //3.28 定义sql：查询账号信息
                String sqluser = "SELECT tu.account,tu.username,tu.orgid,tu.uid,tu.orgid as pid," + "(SELECT name from tbsys_department where id=tu.orgid) as pname," + "(SELECT name from tbsys_department where id=tu.orgid) as orgName," + "tu.email,tu.departid,td.name AS departName,td.level,tu.`position`," + "tp.name AS positionName,tu.roleid,tu.avatar,tr.name AS roleName,tu.unCheckField as unCheckField " + "FROM `tbsys_user_interface` tu " + "JOIN `tbsys_department` td ON tu.departid = td.id " + "JOIN `tbsys_position` tp ON tu.position = tp.id " + "JOIN `tbsys_role` tr ON tu.roleid = tr.id " + "WHERE tu.account= " + "'" + account + "'";
                //3.29、查询安置帮教系统中账号信息，并根据账号信息获取接口密钥
                BeanPropertyRowMapper<UserInterFaceEntity> rowMapper1 = new BeanPropertyRowMapper<>(UserInterFaceEntity.class);
                UserInterFaceEntity userInterface;
                String signature;
                long time = System.currentTimeMillis();
                try {
                    userInterface = jdbcTemplate.queryForObject(sqluser,rowMapper1);
                    String uid = userInterface.getUid();
                    String key;
                    key = Hex.genAccessKey(uid);
                    //客户端自己生成密钥
                    signature = Hex.genSignature(key,String.valueOf(time),"/transmission/api/azbj/savePreArrangedPersonnel/");
                    //3.30、定义json对象，并添加下面节点
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("time",String.valueOf(time));
                    jsonObject.put("sign",signature);
                    jsonObject.put("PrisonerMain",prisonerMain);
                    jsonObject.put("MultimediaInfo",multimediaInfos);
                    jsonObject.put("PrisonerFx",null == prisonerFx ? "" : prisonerFx);
                    jsonObject.put("PrisonerSr",prisonerSrs);
                    jsonObject.put("PrisonerZn",prisonerZns);
                    jsonObject.put("user",userInterface);
                    //3.31、定义返回结果
                    Result result;
                    String flag;
                    if(!StringUtils.isEmpty(azbjPrinum1)) {
                        //3.32-1、更新,如果主表中的安置帮教犯罪编号不为空，说明是更新
                        result = dataTransmissionService.updatePreArrangedPersonnel(JSONObject.toJSON(jsonObject).toString());
                        flag = "update";
                    } else {
                        //3.32-2、新增,如果主表中的安置帮教犯罪编号为空，说明是新数据，或者之前尝试插入安置帮教系统失败
                        result = dataTransmissionService.savePreArrangedPersonnel(JSONObject.toJSON(jsonObject).toString());
                        flag = "insert";
                    }
                    //3.33、根据返回结果，进行后续处理
                    if(Constants.Number.NUM_ONE.equals(result.getCode())) {
                        //3.34-1、成功，修改中间库主表状态state=1，更新各张表的安置帮教犯罪编号
                        String azbjPrinum = (String)result.getData();
                        String sql5 = "update \"azbjMiddle\".prisoner_main set state='1',azbj_prinum='" + azbjPrinum + "' where pri_num='" + prinum + "'";
                        String sql51 = "update \"azbjMiddle\".prisoner_main set update_state='2',azbj_prinum='" + azbjPrinum + "' where pri_num='" + prinum + "'";
                        String sql6 = "update \"azbjMiddle\".prisoner_fx set azbj_prinum='" + azbjPrinum + "' where pri_num='" + prinum + "'";
                        String sql7 = "update \"azbjMiddle\".prisoner_sr set azbj_prinum='" + azbjPrinum + "' where pri_num='" + prinum + "'";
                        String sql8 = "update \"azbjMiddle\".prisoner_zn set azbj_prinum='" + azbjPrinum + "' where pri_num='" + prinum + "'";
                        String sql9 = "update \"azbjMiddle\".prisoner_multimedia set azbj_prinum='" + azbjPrinum + "' where pri_num='" + prinum + "'";
                        String sql10 = "INSERT INTO \"azbjMiddle\".prisoner_middle_log (pri_num, code, create_time, update_time, azbj_prinum)";
                        StringBuilder sb = new StringBuilder(sql10);
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String format = simpleDateFormat.format(date1);
                        sb.append("values (").append("'").append(prinum).append("',").append("'0','").append(format)
                          .append("',").append("'").append(format).append("','").append(azbjPrinum).append("')");
                        if(StringUtils.equals("insert",flag)) {
                            dmJdbcTemplate.execute(sql6);
                            dmJdbcTemplate.execute(sql7);
                            dmJdbcTemplate.execute(sql8);
                            dmJdbcTemplate.execute(sql9);
                        }
                        if(StringUtils.equals("update",flag)) {
                            dmJdbcTemplate.execute(sql51);
                        }
                        dmJdbcTemplate.execute(sql5);
                        dmJdbcTemplate.execute(sb.toString());
                    } else {
                        //3.34-2、失败，修改中间库主表状态state=2，把返回错误码，存储到中间库日志表
                        String code = result.getData().toString();
                        String sql5 = "update \"azbjMiddle\".prisoner_main set state='2' where pri_num='" + prinum + "'";
                        String sql10 = "INSERT INTO \"azbjMiddle\".prisoner_middle_log(pri_num, code, create_time, update_time) ";
                        StringBuilder sb = new StringBuilder(sql10);
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String format = simpleDateFormat.format(date1);
                        sb.append("values (").append("'").append(prinum).append("','").append(code).append("','")
                          .append(format).append("',").append("'").append(format).append("')");
                        dmJdbcTemplate.execute(sql5);
                        dmJdbcTemplate.execute(sb.toString());
                    }
                } catch(EmptyResultDataAccessException e) {
                    log.error("请传递接口用户");
                    String sql6 = "update \"azbjMiddle\".prisoner_main set state='2' where pri_num='" + prinum + "'";
                    String sql11 = "INSERT INTO \"azbjMiddle\".prisoner_middle_log(pri_num, code, create_time, update_time) ";
                    StringBuilder sb = new StringBuilder(sql11);
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String format = simpleDateFormat.format(date1);
                    sb.append("values (").append("'").append(prinum).append("','").append("999999").append("','")
                      .append(format).append("',").append("'").append(format).append("')");
                    dmJdbcTemplate.execute(sql6);
                    dmJdbcTemplate.execute(sb.toString());
                } catch(DataAccessException | InvalidKeyException | NoSuchAlgorithmException e) {
                    log.error("发生异常:",e);
                }
            }
            log.info("\n>>>>>>>>>>>ending......从中间库同步预安置人员数据<<<<<<<<<<");
        } else {
            log.error("检测到数据源不可用,中间库对接数据抽取任务失败!");
        }
    }
}